/* Copyright 2002 -- Ira R. Forman and Nate Forman */ 
/**
 * This transformation creates a subclass that changes no methods,
 * replicates the constructors.  This is more than mathematical completeness
 * (an identity); this transformation makes a good base class for other 
 * transformations that need to replicate constructors and do other things.
 */
//start extract C2IdentitySubclassOfC
package c2c;
import java.lang.reflect.*;
import mopex.*;

public class C2IdentitySubclassOfC extends C2CTransformation {

    static public void main( String[] args ) {                       //#1
	new C2IdentitySubclassOfC().createClass( args );
    }
    
    protected String generateClassNamePrefix() {                     //#2
	return "SubclassOf" + super.generateClassNamePrefix();
    }

    protected String getSuperclass() {return inputClassName;}        //#3

    protected void checkAndProcessArgs( Args args ){                 //#4
	super.checkAndProcessArgs( args );
	if ( inputClassObject.isInterface() )
	    throw new C2CException("input class is an interface");
    }
    
//stop extract C2IdentitySubclassOfC
//    protected String getClassLevelJavadoc() {
//	return "/**\n"
//	    +  " * This class is a subclass of " + inputClassName + "\n"
//	    +  " * that is identical to it. That is, this class has the\n"
//	    +  " * same behavior, because it is subclass that does not\n"
//	    +  " * override any methods or add any data. All constructors\n"
//            +  " * of " +  inputClassName + " are reproduced here.\n"
//	    +  " */\n";
//    }

    /**
     * This method replicates all the constructors declared by the input class.
     */
//start extract C2IdentitySubclassOfC
    protected final String generateConstructors() {                 //#5
	String result = "";
	Constructor[] cArray = inputClassObject.getDeclaredConstructors();
	for (int i = 0; i < cArray.length; i++ )
	    result += "public " 
		   + Mopex.createRenamedConstructor( cArray[i], 
						     outputClassName, 
						     "" );
	return super.generateConstructors() + result;
    }
}
//stop extract C2IdentitySubclassOfC
